package game.services.session;

import com.google.protobuf.GeneratedMessageV3;
import dou.net.protocol.AbstractHandlerRunnable;
import dou.net.protocol.IProtocol;
import dou.net.socket.IClientSocket;
import game.services.MsgID;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import protocol.Session;

public class SessionHandlerRunnable extends AbstractHandlerRunnable
{
    private static Logger logger = LogManager.getLogger("GameServer");

    public SessionHandlerRunnable(int msgID, int msgNum, byte[] bytes, IClientSocket socket, IProtocol protocol)
    {
        super(msgID, msgNum, bytes, socket, protocol);
    }

    public SessionHandlerRunnable(int msgID, int msgNum, GeneratedMessageV3 message, IClientSocket socket, IProtocol protocol)
    {
        super(msgID, msgNum, message, socket, protocol);
    }

    @Override
    protected void errorHandler(String errorStr, Exception exception)
    {
        logger.error(errorStr, exception);
    }

    @Override
    protected GeneratedMessageV3 parseMessage(int msgID, byte[] bytes) throws Exception
    {
        MsgID id = MsgID.get(msgID);
        switch(id)
        {
            case Req_SessionKeepAlive:
                return Session.Req_SessionKeepAlive.parseFrom(bytes);
            case Req_SessionLogin:
                return Session.Req_SessionLogin.parseFrom(bytes);
            case Req_SessionLogout:
                return Session.Req_SessionLogout.parseFrom(bytes);
        }
        return null;
    }
}
